using Game.Networking.Server;
using UnityEngine;

namespace Game {
	public class UnitStats : IStats {
		ComputingUnit _owner;

		public UnitStats(ComputingUnit ower) {
			_owner = ower;
		}

		public uint DeathCount => ServerAgentsController.Instance.GetAgentStats(_owner.ID).DeathCount;

		public uint KillCount => ServerAgentsController.Instance.GetAgentStats(_owner.ID).KillCount;

		public uint Score => ServerAgentsController.Instance.GetAgentStats(_owner.ID).Score;

		public TeamType Team {
			get {
				var agent = ServerAgentsController.Instance.GetAgentEntity(_owner.ID);
				if ( agent != null ) {
					return agent.Team;
				}
				return ServerController.Instance.GetPlayerTeam(_owner.OwnerUser);
			}
		}

		public Vector3 BasePosition => ServerGameController.Instance.GetBaseForTeam(Team)?.transform.position ?? Vector3.zero;

		public uint TeamScore => ServerGameController.Instance.GetBaseForTeam(Team).Score;
	}
}
